#ifndef _ENV_H_
#define _ENV_H_

#define ENV_T_INT   (0)
#define ENV_T_SHORT (1)
#define ENV_T_STR  (2)
#define ENV_T_FLOAT (3)

// 从字符串转换到对应数据结构
struct load_env {
	char *env;		// 环境变量名
	void *output;		// 存储地址
	void *ptr;		// 回调函数参数
	void (*fun)(void *output, char *val, void *ptr);	// 回调函数
	int type;		// 数据类型
};


#define ENV_SIZE (512)

// 环境变量存储于FLASH的结构
struct sys_env {
	unsigned int hash;	// env内容的hash值
	char env[ENV_SIZE];	// 环境变量内容，各变量之间用 \0 间隔
				// 所有变量以 \0\0 结束
				// ENV_SIZE 的长度包括末尾的 \0\0
};

#define ENV_DEF \
	"sn=[xxxx\0"				\
							\
	"ch1_10_adc=351\0ch1_10_dac=601\0"		\
	"ch2_10_adc=352\0ch2_10_dac=602\0"		\
	"ch3_10_adc=353\0ch3_10_dac=603\0"		\
							\
	"lv1_low=127\0lv1_high=1950\0"			\
	"lv2_low=127\0lv2_high=1950\0"			\
	"lv3_low=126\0lv3_high=1302\0"			\
	"lv4_low=129\0lv4_high=1277\0"			\
	"lv5_low=100\0lv5_high=1320\0"			\
	"lv6_low=206\0lv6_high=1023\0"			\
	"lv7_low=213\0lv7_high=2136\0"			\
							\
	"ch1_wave=61310\0"				\
	"ch2_wave=61550\0"				\
	"ch3_wave=61490\0"				\
							\
	"ch1_en=1\0"					\
	"ch2_en=1\0"					\
	"ch3_en=1\0"					\
	"_1550_ref_1310=1.0155\0"			\
	"_1490_ref_1310=1.0490\0"			\
	"_1625_ref_1310=1.0625\0"			\
	"_850_ref_1310=1.085\0"				\
	"\0"

extern char *_do_getenv(char *find);
extern void _do_setenv(char *name, char *val);
extern void do_printenv();
extern int isvalid_env();
extern int copy_def_env();
extern int total_env_len(char *in_env);
extern int envtostr(void *output, char *env, void *ptr);
extern int envtoi(void *output, char *env, void *ptr);
extern int envtos(void *output, char *env, void *ptr);
extern int envtof(void *output, char *env, void *ptr);

extern void env_2_system(struct load_env *sys_vals, int count);
#endif
